package com.handyshop.mall.user.controller;

import com.handyshop.mall.basic.core.vo.ResultVo;
import com.handyshop.mall.dubbo.user.entity.SysUser;
import com.handyshop.mall.user.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author hs
 * @date 2020/11/30
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysUser")
@Api(tags = "用户管理模块")
public class SysUserController {

    private final SysUserService userService;

    @DeleteMapping("/{id}")
    //@PreAuthorize("@pms.hasPermission('sys_user_del')")
    @ApiOperation(value = "删除用户信息")
    public ResultVo<Boolean> userDel(@PathVariable Integer id) {
        return ResultVo.success(userService.removeById(id));
    }

    @PostMapping("/add")
    @ApiOperation(value = "添加用户")
    //@PreAuthorize("@pms.hasPermission('sys_user_add')")
    public ResultVo<Boolean> user(@RequestBody SysUser sysUser) {
        return ResultVo.success(userService.save(sysUser));
    }

    @PutMapping("/edit")
    @ApiOperation(value = "更新用户信息")
    //@PreAuthorize("@pms.hasPermission('sys_user_edit')")
    public ResultVo<Boolean> updateUser(@Validated @RequestBody SysUser userDto) {
        return ResultVo.success(userService.updateById(userDto));
    }

}
